package me.zhengjie.modules.web.service.advert.impl;

import me.zhengjie.modules.system.service.AdvertService;
import me.zhengjie.modules.system.service.dto.AdvertDto;
import me.zhengjie.modules.system.service.dto.AdvertQueryCriteria;
import me.zhengjie.modules.web.domain.advert.AdvertResp;
import me.zhengjie.modules.web.service.advert.IAdvertWebService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王宇
 */
@Service
public class AdvertWebServiceImpl implements IAdvertWebService {
    @Autowired
    private AdvertService advertService;

    @Override
    public List<AdvertResp> advertList(String type) {
        AdvertQueryCriteria advertQueryCriteria = new AdvertQueryCriteria();
        advertQueryCriteria.setStatus("0");
        advertQueryCriteria.setType(type);
        List<AdvertDto> list = advertService.queryAll(advertQueryCriteria);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        List<AdvertResp> resps = new ArrayList<>();
        list.forEach(s -> {
            AdvertResp resp = new AdvertResp();
            BeanUtils.copyProperties(s, resp);
            resps.add(resp);
        });
        return resps;
    }
}